package fr.ginvest.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "participation")
public class Participation implements Serializable {

	private static final long serialVersionUID = 1L;
	public enum ENTANTQUE{ANGEL, FONDATEUR, GROUPE}
	public enum ETAT{DECLAREE, VALIDEE}
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private int id;
	
	@Basic(optional=false)
	private double montant;
	
	@Temporal(TemporalType.DATE)
	private java.util.Date dateParticipation;
	
	@Basic(optional=false)
	private ENTANTQUE typeInvest;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name="id_investisseur", nullable=false)
	private Investisseur investisseur;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name="id_startup", nullable=false)
	private Startup startup;
	
	@Enumerated(EnumType.STRING)
	@Column(length=8, nullable=false)
	private ETAT etat;
		
	public Participation() {}

	public Participation(int montant, Date dateParticipation) {
		this.montant = montant;
		this.dateParticipation = dateParticipation;
	}

	public Participation(double montant, Date dateParticipation, ENTANTQUE typeInvest,
			Investisseur investisseur, Startup startup) {
		super();
		this.montant = montant;
		this.dateParticipation = dateParticipation;
		this.typeInvest = typeInvest;
		this.investisseur = investisseur;
		this.startup = startup;
		this.etat = ETAT.DECLAREE;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Participation other = (Participation) obj;
		if (id != other.id)
			return false;
		return true;
	}

	
	@Column(name = "id", unique = true, nullable = false)
	@GeneratedValue(strategy=GenerationType.AUTO)
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	@Column(name = "montant")
	public double getMontant() {
		return montant;
	}

	public void setMontant(double f) {
		this.montant = f;
	}

	@Column(name = "dateParticipation")
	public java.util.Date getDateParticipation() {
		return dateParticipation;
	}

	public void setDateParticipation(java.util.Date dateParticipation) {
		this.dateParticipation = dateParticipation;
	}
	
	public Investisseur getInvestisseur() {
		return investisseur;
	}

	public void setInvestisseur(Investisseur investisseur) {
		this.investisseur = investisseur;
	}

	@Column(name = "typeInvest", nullable=true)
	public ENTANTQUE getTypeInvest() {
		return typeInvest;
	}

	public void setTypeInvest(ENTANTQUE typeInvest) {
		this.typeInvest = typeInvest;
	}
	
	public Startup getStartup() {
		return this.startup;
	}

	public void setStartup(Startup startup) {
		this.startup = startup;
	}

	public ETAT getEtat() {
		return etat;
	}

	public void setEtat(ETAT etat) {
		this.etat = etat;
	}
	
}
